package com.yu.boot.admin.web;

import com.yu.boot.admin.service.CategoryService;
import com.yu.boot.config.YuProperties;
import com.yu.boot.lib.util.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 */
@Controller
@RequestMapping("")
public class MainController {

    @Autowired
    CategoryService categoryService;

    @Autowired
    HttpServletRequest request;

    @Autowired
    YuProperties yuProperties;

    @RequestMapping("main")
    public String index() {
        String userName = AuthUtil.getUserName(request);
        int i = categoryService.countCategoryByUserName(userName);
        Object redirectPlugined = request.getSession().getAttribute("redirectPlugined");
        if (i == 0 && redirectPlugined == null) {
            request.getSession().setAttribute("redirectPlugined", true);
            return "redirect:plugin";
        }
        return "main";
    }

    @RequestMapping("plugin")
    public String plugin(ModelMap map) {
        String serverUrl = yuProperties.getServerUrl();
        map.put("serverUrl",serverUrl);
        return "plugin";
    }

    @RequestMapping("discovery")
    public String discovery() {
        return "discovery";
    }

    @RequestMapping("collect")
    public String collect(ModelMap map,String url, String description,String title) {
        return "collect";
    }

    @RequestMapping("categoryCover/view")
    public String view(){
        return "cover";
    }


}
